package assdraw2.toolbaragent.presentation;

import java.awt.FlowLayout;

import javax.swing.JFrame;

import assdraw2.canvas.abstraction.command.CircleCommand;
import assdraw2.canvas.abstraction.command.LineCommand;
import assdraw2.canvas.abstraction.command.RectCommand;
import assdraw2.canvas.abstraction.command.TriangleCommand;
import assdraw2.common.MessageType;
import assdraw2.common.PACAgent;
import assdraw2.common.PACMessage;
import assdraw2.common.PresentationWindowListener;
import assdraw2.toolbaragent.ToolbarControl;

public class ToolbarPresentation extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private PACAgent control;

	public ToolbarPresentation(ToolbarControl control) {
		super("Toolbar");
		this.control = control;

		setResizable(false);
		//setLayout(new GridLayout(1, 13));
		setLayout(new FlowLayout());
		
		initComponents();
		
		//this.setPreferredSize(new Dimension(1000, 60));
		this.pack();
		this.setVisible(true);
		
		setLocation(400,30);
		
		addWindowListener(new PresentationWindowListener(control));
	}

	private void initComponents() {

    	toolsButtonGroup = new javax.swing.ButtonGroup();
    	
        lineButton = new javax.swing.JToggleButton();
        rectangleButton = new javax.swing.JToggleButton();
        circleButton = new javax.swing.JToggleButton();
        triangleButton = new javax.swing.JToggleButton();
        jSeparator1 = new javax.swing.JSeparator();
        groupButton = new javax.swing.JButton();
        ungroupButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        sizeUpButton = new javax.swing.JButton();
        sizeDownButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        zoomInButton = new javax.swing.JButton();
        zoomOutButton = new javax.swing.JButton();
        
        
        toolsButtonGroup.add(lineButton);
        lineButton.setSelected(true);
        lineButton.setText("Line");
        lineButton.setFocusable(false);
        lineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lineButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        lineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.TOOL, control, new LineCommand()));
            }
        });
        add(lineButton);

        toolsButtonGroup.add(rectangleButton);
        rectangleButton.setText("Rectangle");
        rectangleButton.setFocusable(false);
        rectangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        rectangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rectangleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.TOOL, control, new RectCommand()));
            }
        });
        add(rectangleButton);

        toolsButtonGroup.add(circleButton);
        circleButton.setText("Circle");
        circleButton.setFocusable(false);
        circleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        circleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        circleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.TOOL, control, new CircleCommand()));
            }
        });
        add(circleButton);

        toolsButtonGroup.add(triangleButton);
        triangleButton.setText("Triangle");
        triangleButton.setFocusable(false);
        triangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        triangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        triangleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.TOOL, control, new TriangleCommand()));
            }
        });
        add(triangleButton);
        add(jSeparator1);
        
        groupButton.setText("Group");
        groupButton.setFocusable(false);
        groupButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        groupButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        groupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.SHAPE_GROUP, control));
            }
        });
        add(groupButton);

        ungroupButton.setText("Ungroup");
        ungroupButton.setFocusable(false);
        ungroupButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        ungroupButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ungroupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.SHAPE_UNGROUP, control));
            }
        });
        add(ungroupButton);
        add(jSeparator2);
        
        sizeUpButton.setText("Size Up");
        sizeUpButton.setToolTipText("");
        sizeUpButton.setFocusable(false);
        sizeUpButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sizeUpButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sizeUpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.SIZE_UP, control));
            }
        });
        add(sizeUpButton);

        sizeDownButton.setText("Size Down");
        sizeDownButton.setFocusable(false);
        sizeDownButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sizeDownButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sizeDownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.SIZE_DOWN, control));
            }
        });
        add(sizeDownButton);
        add(jSeparator3);

        zoomInButton.setText("Zoom In");
        zoomInButton.setFocusable(false);
        zoomInButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomInButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomInButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.ZOOM_IN, control));     
            }
        });
        add(zoomInButton);

        zoomOutButton.setText("Zoom Out");
        zoomOutButton.setFocusable(false);
        zoomOutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomOutButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);zoomOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	control.sendMessage(new PACMessage(MessageType.ZOOM_OUT, control));  
            }
        });
        
        add(zoomOutButton);        

        
    }	

    private javax.swing.JToggleButton lineButton;
    private javax.swing.JToggleButton circleButton;
    private javax.swing.JButton groupButton;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JToggleButton rectangleButton;
    private javax.swing.JToggleButton triangleButton;
    private javax.swing.JButton ungroupButton;
    private javax.swing.JButton zoomInButton;
    private javax.swing.JButton zoomOutButton;
    private javax.swing.JButton sizeDownButton;
    private javax.swing.JButton sizeUpButton;
	private javax.swing.ButtonGroup toolsButtonGroup;

	
}
